package ams.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import ams.model.entity.Org;
import ams.service.IOrgService;

@Namespace("/org")
public class OrgAction extends BaseAction<Org> implements ModelDriven<Org> {

	private static final long serialVersionUID = 1L;

	
	@Autowired
	private IOrgService orgService;
	
	private Org org = new Org();
	
	private List<Org> orgList = new ArrayList<>();
	
	@Action(value="orgAdmin",results={@Result(location="/WEB-INF/jsp/org.jsp")})
	public String orgAdmin(){
		return SUCCESS;
	}

	@Action(value = "add", results = { 
			@Result(type = "json", params = {"root", "execResult", "excludeNullProperties","true", "contentType", "text/html" }) })
	public String add() {
		super.execResult = orgService.add(org);
		return SUCCESS;
	}

	@Action(value = "delete", results = { 
			@Result(type = "json", params = {"root", "execResult", "excludeNullProperties","true" }) })
	public String delete() {
		super.execResult = orgService.delete(org);
		return SUCCESS;
	}

	@Action(value = "update", results = { 
			@Result(type = "json", params = {"root", "execResult", "excludeNullProperties","true", "contentType", "text/html" }) })
	public String update() {
		super.execResult = orgService.update(org);
		return SUCCESS;
	}

	@Action(value = "getOrgByPid", results = { 
			@Result(type = "json", params = {"root", "orgList", "excludeNullProperties","true" }) })
	public String getOrgByPid() {
		orgList = orgService.getOrgByPid(org.getId());
		return SUCCESS;
	}
	
	@Action(value = "getOrgCatalog", results = { 
			@Result(type = "json", params = {"root", "orgList", "excludeNullProperties","true" }) })
	public String getOrgCatalog() {
		orgList = orgService.getOrgCatalog();
		return SUCCESS;
	}

	@Override
	public Org getModel() {
		return org;
	}

	public List<Org> getOrgList() {
		return orgList;
	}

	public void setOrgList(List<Org> orgList) {
		this.orgList = orgList;
	}
	
	

}
